Task 4: Exploratory Data Analysis - Terrorism¶

Author: Mahmoud Ahmed Shimy¶

Table of Contents¶

  • Introduction
  • Data Wrangling
  • Exploratory Data Analysis (EDA )
  • Conclusions

Introduction¶

Important note:¶

All the conclusions, results, and recommendations are derived according to this dataset which is not considering the World Wars as terrorist acts and did not waste the lives of millions of people.

Dataset Description¶

I have selected the Global Terrorism dataset to investigate it and do some Exploratory Data Analysis by exploring the correlations between the varies things on it and find patterns to find out the hot zones of terrorism and get all security issues and insights I can derive by answering some question that we will ask now.

Question(s) for Analysis¶

  1. First step after importing and wrangling the data is to check the Uni-Variate Analysis by getting the top 5 countries, Governates and Regions by number of attacks. and starts here
  2. Also it is important to know the most used types of attacks and targets globally. here
  3. Going to Bi-Variate analysis it's important to answer some questions like what is the most countries, regions has kills and kills per attack and the most target, attack type in each zone. here
  4. Finally with Multi-Variate Analysis we need to know the most target and attack type in each country in the Region and starts here

importing Liberaries and DataFrame¶

This section is to import the necessary liberaries and DataFrame

In [1]:
# for data frames
import pandas as pd
# for numerical fn.
import numpy as np
# for data visualization
import matplotlib.pyplot as plt
%matplotlib inline
import datetime as dt
from pandas_profiling import ProfileReport
C:\Users\ip\AppData\Local\Temp\ipykernel_9692\1908016125.py:9: DeprecationWarning: `import pandas_profiling` is going to be deprecated by April 1st. Please use `import ydata_profiling` instead.
  from pandas_profiling import ProfileReport
In [2]:
# pip install ipywidgets
# pip install pandas-profiling

Data Wrangling section¶

In this section we will do some gathering, assessing and cleaning to the data to be more suatable and easy to analyse

In [3]:
df = pd.read_csv("globalterrorismdb_0718dist.csv", encoding='latin-1')
C:\Users\ip\AppData\Local\Temp\ipykernel_9692\2266119131.py:1: DtypeWarning: Columns (4,6,31,33,61,62,63,76,79,90,92,94,96,114,115,121) have mixed types. Specify dtype option on import or set low_memory=False.
  df = pd.read_csv("globalterrorismdb_0718dist.csv", encoding='latin-1')
In [4]:
df.shape
Out[4]:
(181691, 135)

Now we know that the data has about 180k observations and 135 column.

Lets look at 3 random observations.

In [5]:
# to see all columns
pd.set_option('display.max_columns', None)
df.sample(3)
Out[5]:
eventid iyear imonth iday approxdate extended resolution country country_txt region region_txt provstate city latitude longitude specificity vicinity location summary crit1 crit2 crit3 doubtterr alternative alternative_txt multiple success suicide attacktype1 attacktype1_txt attacktype2 attacktype2_txt attacktype3 attacktype3_txt targtype1 targtype1_txt targsubtype1 targsubtype1_txt corp1 target1 natlty1 natlty1_txt targtype2 targtype2_txt targsubtype2 targsubtype2_txt corp2 target2 natlty2 natlty2_txt targtype3 targtype3_txt targsubtype3 targsubtype3_txt corp3 target3 natlty3 natlty3_txt gname gsubname gname2 gsubname2 gname3 gsubname3 motive guncertain1 guncertain2 guncertain3 individual nperps nperpcap claimed claimmode claimmode_txt claim2 claimmode2 claimmode2_txt claim3 claimmode3 claimmode3_txt compclaim weaptype1 weaptype1_txt weapsubtype1 weapsubtype1_txt weaptype2 weaptype2_txt weapsubtype2 weapsubtype2_txt weaptype3 weaptype3_txt weapsubtype3 weapsubtype3_txt weaptype4 weaptype4_txt weapsubtype4 weapsubtype4_txt weapdetail nkill nkillus nkillter nwound nwoundus nwoundte property propextent propextent_txt propvalue propcomment ishostkid nhostkid nhostkidus nhours ndays divert kidhijcountry ransom ransomamt ransomamtus ransompaid ransompaidus ransomnote hostkidoutcome hostkidoutcome_txt nreleased addnotes scite1 scite2 scite3 dbsource INT_LOG INT_IDEO INT_MISC INT_ANY related
135329 201407210019 2014 7 21 NaN 0 NaN 4 Afghanistan 6 South Asia Faryab Qaysar district 35.687416 64.293102 3.0 0 NaN 07/21/2014: A roadside bomb detonated in Qaysa... 1 1 1 0.0 NaN NaN 0.0 1 0 3 Bombing/Explosion NaN NaN NaN NaN 14 Private Citizens & Property 67.0 Unnamed Civilian/Unspecified Not Applicable Civilians 4.0 Afghanistan NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Unknown NaN NaN NaN NaN NaN NaN 0.0 NaN NaN 0 -99.0 0.0 0.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN 6 Explosives 16.0 Unknown Explosive Type NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN A roadside bomb was used in the attack. 2.0 0.0 0.0 4.0 0.0 0.0 0 NaN NaN NaN NaN 0.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN The victims were family members of an Afghan N... "Afghanistan: Two Civilians, 15 Insurgents, 8 ... NaN NaN START Primary Collection -9 -9 0 -9 NaN
6072 197803060001 1978 3 6 NaN 0 NaN 130 Mexico 1 North America Jalisco Guadalajara 20.673343 -103.344177 1.0 0 NaN NaN 1 1 1 0.0 NaN NaN 0.0 1 0 3 Bombing/Explosion NaN NaN NaN NaN 1 Business 3.0 Bank/Commerce NaN Bank 130.0 Mexico NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Union of the People (UDP) NaN NaN NaN NaN NaN NaN 0.0 NaN NaN 0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 6 Explosives 16.0 Unknown Explosive Type NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN Explosive NaN NaN NaN NaN NaN NaN 1 NaN NaN NaN NaN 0.0 NaN NaN NaN NaN NaN NaN 0.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN PGIS 0 0 0 0 NaN
171289 201701180030 2017 1 18 January 15-21, 2017 0 NaN 45 Colombia 3 South America Unknown Unknown NaN NaN 5.0 0 The incident occurred in either Norte de Santa... 01/00/2017: Sometime between January 15, 2017 ... 1 1 1 0.0 NaN NaN 1.0 1 0 3 Bombing/Explosion NaN NaN NaN NaN 21 Utilities 108.0 Oil Ecopetrol Cano Limon-Covenas Oil Pipeline 45.0 Colombia NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN National Liberation Army of Colombia (ELN) NaN NaN NaN NaN NaN NaN 0.0 NaN NaN 0 -99.0 0.0 0.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN 6 Explosives 16.0 Unknown Explosive Type NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN 0.0 0.0 0.0 0.0 0.0 0.0 1 4.0 Unknown -99.0 An oil pipeline was damaged in this attack. 0.0 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN "Bombings halted pumping at Colombia's Cano-Li... "Wave of Attacks Hit Colombia Pipeline," Energ... NaN START Primary Collection 0 0 0 0 201701180024, 201701180025, 201701180026, 2017...

Data Assessing & Cleaning¶

After gathering the data it has some problems and needs to be cleand so let's take a look on some of these problems.

Firstly there's many columns that we will not use lets take what we need from columns.

In [6]:
df = df[["eventid","iday", "iyear", "imonth", "country_txt", "region_txt", "provstate", "city", "latitude", "longitude", "success", "attacktype1_txt","nkill", "target1"]]
In [7]:
df.shape
Out[7]:
(181691, 14)

Now it has 15 columns

In [8]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 181691 entries, 0 to 181690
Data columns (total 14 columns):
 #   Column           Non-Null Count   Dtype  
---  ------           --------------   -----  
 0   eventid          181691 non-null  int64  
 1   iday             181691 non-null  int64  
 2   iyear            181691 non-null  int64  
 3   imonth           181691 non-null  int64  
 4   country_txt      181691 non-null  object 
 5   region_txt       181691 non-null  object 
 6   provstate        181270 non-null  object 
 7   city             181257 non-null  object 
 8   latitude         177135 non-null  float64
 9   longitude        177134 non-null  float64
 10  success          181691 non-null  int64  
 11  attacktype1_txt  181691 non-null  object 
 12  nkill            171378 non-null  float64
 13  target1          181055 non-null  object 
dtypes: float64(3), int64(5), object(6)
memory usage: 19.4+ MB
In [9]:
df[df.city == "Unknown"].sample(2)
Out[9]:
eventid iday iyear imonth country_txt region_txt provstate city latitude longitude success attacktype1_txt nkill target1
54327 199212030028 3 1992 12 France Western Europe Corsica Unknown 41.918891 8.737554 1 Bombing/Explosion 0.0 Office
168072 201610130036 13 2016 10 India South Asia Uttar Pradesh Unknown 26.846708 80.946159 0 Assassination 0.0 Vehicle of Consultant of Chief Minister: Sanja...

I've noticed that there's many Unknown cities
lets make it null values

In [10]:
df.replace("Unknown", np.nan, inplace=True)
In [11]:
df[df.iday == 0].sample(2)
Out[11]:
eventid iday iyear imonth country_txt region_txt provstate city latitude longitude success attacktype1_txt nkill target1
5334 197710000002 0 1977 10 Colombia South America Antioquia Medellin 6.242026 -75.564766 1 Hostage Taking (Kidnapping) 0.0 Gilberto Restrepo Velez, landowner
102946 201109010010 0 2011 9 India South Asia Chhattisgarh Raipur 21.251384 81.629641 0 Bombing/Explosion 0.0 The targets of the attempted bombing were poli...

There's many days and months is 0
let's make it Null

In [12]:
df[["iday", "imonth"]] = df[["iday", "imonth"]].replace(0, np.nan)
In [13]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 181691 entries, 0 to 181690
Data columns (total 14 columns):
 #   Column           Non-Null Count   Dtype  
---  ------           --------------   -----  
 0   eventid          181691 non-null  int64  
 1   iday             180800 non-null  float64
 2   iyear            181691 non-null  int64  
 3   imonth           181671 non-null  float64
 4   country_txt      181691 non-null  object 
 5   region_txt       181691 non-null  object 
 6   provstate        176980 non-null  object 
 7   city             171482 non-null  object 
 8   latitude         177135 non-null  float64
 9   longitude        177134 non-null  float64
 10  success          181691 non-null  int64  
 11  attacktype1_txt  174415 non-null  object 
 12  nkill            171378 non-null  float64
 13  target1          175137 non-null  object 
dtypes: float64(5), int64(3), object(6)
memory usage: 19.4+ MB
In [14]:
df.dropna(inplace=True)
In [15]:
df.duplicated().sum()
Out[15]:
0
In [16]:
df.drop_duplicates(inplace=True)
In [17]:
df.sample(2)
Out[17]:
eventid iday iyear imonth country_txt region_txt provstate city latitude longitude success attacktype1_txt nkill target1
44845 199012110011 11.0 1990 12.0 Philippines Southeast Asia Metropolitian Manila Manila 14.596051 120.978666 1 Assassination 1.0 Patrolman assigned to western police dist. hom...
73362 200111150006 15.0 2001 11.0 Sri Lanka South Asia Eastern Batticaloa 7.733107 81.688820 1 Bombing/Explosion 4.0 Former Liberation Tigers of Tamil Eelam (LTTE)...

Now lets creat a new columns calles date

In [18]:
df["date"] = pd.to_datetime(dict(year = df.iyear, month = df.imonth, day = df.iday))

Also lets make the 'eventid' as index for our data then drop it.

In [19]:
df.set_index(df.eventid, inplace=True)
df.sample()
Out[19]:
eventid iday iyear imonth country_txt region_txt provstate city latitude longitude success attacktype1_txt nkill target1 date
eventid
200703270013 200703270013 27.0 2007 3.0 Iraq Middle East & North Africa Baghdad Baghdad 33.303566 44.371773 1 Armed Assault 3.0 Waqf Officers in Baghdad 2007-03-27
In [20]:
df.eventid.duplicated().sum()
Out[20]:
0
In [21]:
df.drop(columns="eventid",inplace=True)

As a final step in cleaning data lets rename all columns to be easier to read.

In [22]:
df.rename(columns={"iday" : "day", "iyear" : "year", "imonth" : "month", "region_txt" : "region", "provstate" : "state", "attacktype1_txt" : "attack_type", "target1" : "target", "country_txt" : "country"}, inplace=True)
In [23]:
df.head(3)
Out[23]:
day year month country region state city latitude longitude success attack_type nkill target date
eventid
197001010002 1.0 1970 1.0 United States North America Illinois Cairo 37.005105 -89.176269 1 Armed Assault 0.0 Cairo Police Headquarters 1970-01-01
197001020001 2.0 1970 1.0 Uruguay South America Montevideo Montevideo -34.891151 -56.187214 0 Assassination 0.0 Juan Maria de Lucah/Chief of Directorate of in... 1970-01-02
197001020002 2.0 1970 1.0 United States North America California Oakland 37.791927 -122.225906 1 Bombing/Explosion 0.0 Edes Substation 1970-01-02
In [24]:
df.day = df.day.astype(int)
df.month = df.month.astype(int)
df.nkill = df.nkill.astype(int)
In [25]:
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 147519 entries, 197001010002 to 201712310031
Data columns (total 14 columns):
 #   Column       Non-Null Count   Dtype         
---  ------       --------------   -----         
 0   day          147519 non-null  int32         
 1   year         147519 non-null  int64         
 2   month        147519 non-null  int32         
 3   country      147519 non-null  object        
 4   region       147519 non-null  object        
 5   state        147519 non-null  object        
 6   city         147519 non-null  object        
 7   latitude     147519 non-null  float64       
 8   longitude    147519 non-null  float64       
 9   success      147519 non-null  int64         
 10  attack_type  147519 non-null  object        
 11  nkill        147519 non-null  int32         
 12  target       147519 non-null  object        
 13  date         147519 non-null  datetime64[ns]
dtypes: datetime64[ns](1), float64(2), int32(3), int64(2), object(6)
memory usage: 15.2+ MB
In [26]:
df.describe()
Out[26]:
day year month latitude longitude success nkill
count 147519.000000 147519.000000 147519.000000 147519.000000 1.475190e+05 147519.000000 147519.000000
mean 15.587802 2003.027454 6.471336 23.884283 -5.552770e+02 0.904541 2.307974
std 8.767093 12.979404 3.389837 18.694646 2.243946e+05 0.293849 11.703643
min 1.000000 1970.000000 1.000000 -53.154613 -8.618590e+07 0.000000 0.000000
25% 8.000000 1991.000000 4.000000 11.707204 5.908448e+00 1.000000 0.000000
50% 15.000000 2009.000000 6.000000 31.633078 4.349141e+01 1.000000 0.000000
75% 23.000000 2014.000000 9.000000 34.816667 6.902103e+01 1.000000 2.000000
max 31.000000 2017.000000 12.000000 74.633553 1.793667e+02 1.000000 1570.000000

Now we have cleaned data without missing or duplicated values and ready to be explored

Exploring Data Section (EDA)¶

After wrangling the data, In this section we will answer some questions by analysing the data to create some Conclusions about the dataframe. All these questions is from my deep mind and of course you may have different questions so don't be restricted by this questions.

In [27]:
ProfileReport(df)
Summarize dataset:   0%|          | 0/5 [00:00<?, ?it/s]
Generate report structure:   0%|          | 0/1 [00:00<?, ?it/s]
Render HTML:   0%|          | 0/1 [00:00<?, ?it/s]
Out[27]:

In [28]:
df.sample(2)
Out[28]:
day year month country region state city latitude longitude success attack_type nkill target date
eventid
201403090024 9 2014 3 Iraq Middle East & North Africa Saladin Hay al-Qadisiyah 34.458889 43.791004 1 Assassination 1 Mayor 2014-03-09
201407050047 5 2014 7 Afghanistan South Asia Zabul Shahjoy district 32.503195 67.415893 1 Bombing/Explosion 2 Vehicle 2014-07-05

Uni-variate analysis¶

In [29]:
def pltbar(datax, datay, namex, namey, title):
    plt.bar(
    x = datax,
    height = datay
    )
    plt.xlabel(namex, fontsize = 15)
    plt.ylabel(namey, fontsize = 15)
    plt.title(title, fontsize = 15)
In [30]:
# City
print("Top 5 countries\n",df.country.value_counts()[:5])
Top 5 countries
 Iraq           21066
Pakistan       12987
India          10163
Afghanistan     9523
Colombia        6379
Name: country, dtype: int64
In [31]:
pltbar(df.country.value_counts()[:5].index, df.country.value_counts()[:5].values, "Country", "# Terrorism act", "Top 5 Countries")
In [32]:
# State
print("Top 5 Governates\n",df.state.value_counts()[:5])
pltbar(df.state.value_counts()[:5].index, df.state.value_counts()[:5].values, "Governate", "# Terrorism act", "Top 5 Governates")
plt.xticks(rotation = 45);
Top 5 Governates
 Baghdad             7129
Northern Ireland    4158
Balochistan         3255
Sindh               3030
Saladin             2838
Name: state, dtype: int64
In [33]:
# Region
print("Top 5 Regions\n",df["region"].value_counts()[:5])
pltbar(df.region.value_counts()[:5].index, df.region.value_counts()[:5].values, "Region", "# Terrorism act", "Top 5 Regions")
plt.xticks(rotation = 45);
Top 5 Regions
 Middle East & North Africa    41296
South Asia                    37717
South America                 15001
Western Europe                14498
Sub-Saharan Africa            13534
Name: region, dtype: int64

In [34]:
# type
print("Top 5 Type of attacks\n",df.attack_type.value_counts()[:5])
pltbar(df.attack_type.value_counts()[:5].index, df.attack_type.value_counts()[:5].values, "Type", "# Terrorism act", "Top 5 Type of attacks")
plt.xticks(rotation = 45);
Top 5 Type of attacks
 Bombing/Explosion                 74250
Armed Assault                     36442
Assassination                     17897
Facility/Infrastructure Attack     9150
Hostage Taking (Kidnapping)        7529
Name: attack_type, dtype: int64
In [35]:
# target
print("Top 5 Targets\n",df.target.value_counts()[:5])
pltbar(df.target.value_counts()[:5].index, df.target.value_counts()[:5].values, "Target", "# Terrorism act", "Top 5 Targets")
Top 5 Targets
 Civilians     5688
Patrol        2693
Vehicle       2533
Checkpoint    2411
Soldiers      2261
Name: target, dtype: int64
In [36]:
# success
plt.pie(df.groupby(df.success).count().day, labels=["Failed", "Succeeded"], autopct='%.2f%%',
       wedgeprops={'linewidth': 2.0, 'edgecolor': 'white'},
       textprops={'size': 'x-large'});
plt.title('Attack Success', fontsize=18)
df.groupby(df.success).count().day
Out[36]:
success
0     14082
1    133437
Name: day, dtype: int64
In [37]:
# Year
df.year.value_counts()[:5]
Out[37]:
2014    13721
2015    11938
2016    10540
2013    10407
2017     8341
Name: year, dtype: int64
In [38]:
# Numerical Data
df.describe()
Out[38]:
day year month latitude longitude success nkill
count 147519.000000 147519.000000 147519.000000 147519.000000 1.475190e+05 147519.000000 147519.000000
mean 15.587802 2003.027454 6.471336 23.884283 -5.552770e+02 0.904541 2.307974
std 8.767093 12.979404 3.389837 18.694646 2.243946e+05 0.293849 11.703643
min 1.000000 1970.000000 1.000000 -53.154613 -8.618590e+07 0.000000 0.000000
25% 8.000000 1991.000000 4.000000 11.707204 5.908448e+00 1.000000 0.000000
50% 15.000000 2009.000000 6.000000 31.633078 4.349141e+01 1.000000 0.000000
75% 23.000000 2014.000000 9.000000 34.816667 6.902103e+01 1.000000 2.000000
max 31.000000 2017.000000 12.000000 74.633553 1.793667e+02 1.000000 1570.000000

Bi-Variate Analysis¶

Q1: what is the most country has kills?

In [39]:
pltbar(df.groupby(df.country).sum().sort_values(by="nkill", ascending=False)[:5].nkill.index,  df.groupby(df.country).sum().sort_values(by="nkill", ascending=False)[:5].nkill.values, "Country", "#of kills", "Top 5 countries has kills")
df.groupby(df.country).sum().sort_values(by="nkill", ascending=False)[:5].nkill
Out[39]:
country
Iraq           68408
Afghanistan    31385
Pakistan       22552
Nigeria        21201
India          16236
Name: nkill, dtype: int32

Q2: What is the top 5 countries in average kills by attack?

In [40]:
pltbar(df.groupby(df.country).mean().sort_values("nkill", ascending=False)[1:6].index, df.groupby(df.country).mean().sort_values("nkill", ascending=False).nkill[1:6].values, "Country", "Average kills by attack", "Top 5 countries in average kills by attack")
df.groupby(df.country).mean().sort_values("nkill", ascending=False)[:6]
Out[40]:
day year month latitude longitude success nkill
country
South Vietnam 15.000000 1972.000000 6.000000 13.977956 108.002298 1.000000 81.000000
Barbados 14.000000 1981.333333 6.333333 13.126551 -59.545478 1.000000 25.333333
Rwanda 14.322835 1998.464567 5.031496 -1.958385 29.835836 0.968504 19.811024
South Sudan 15.172662 2015.402878 6.323741 6.564728 30.774401 0.906475 14.323741
Djibouti 15.882353 1992.764706 6.117647 11.584890 42.953165 1.000000 11.647059
Niger 14.917431 2008.788991 5.972477 15.051038 8.122337 0.963303 10.532110

Q3: What is the most target in each country?

In [41]:
for x in df.groupby(df.country).sum().sort_values(by="country").index:
    print("The most target in",x,"is",df[df.country == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.country == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most target in Afghanistan is Vehicle with [659] attacks
The most target in Albania is bridge with [3] attacks
The most target in Algeria is Unit with [55] attacks
The most target in Angola is High tension line tower with [113] attacks
The most target in Argentina is office with [19] attacks
The most target in Armenia is Andranik Markarian with [1] attacks
The most target in Australia is Church with [8] attacks
The most target in Austria is Embassy Official with [5] attacks
The most target in Azerbaijan is Afiyaddin Jalilou, Deputy to Parliament Chairman with [1] attacks
The most target in Bahamas is Car and home of Norman Solomon leader of Social Democratic Party with [1] attacks
The most target in Bahrain is Officers with [28] attacks
The most target in Bangladesh is Bus with [60] attacks
The most target in Barbados is British West Indies Airways Offices with [1] attacks
The most target in Belarus is A prison was targeted in the attack. with [1] attacks
The most target in Belgium is Embassy Official with [3] attacks
The most target in Belize is Car of Minister of State, Mr. V.H. Courtenay with [1] attacks
The most target in Benin is Bar-Restaurant with [1] attacks
The most target in Bhutan is Bhutan Oil Distributor's petrol pump with [1] attacks
The most target in Bolivia is office with [12] attacks
The most target in Bosnia-Herzegovina is Unk with [5] attacks
The most target in Botswana is Abraham Onkgopotse Tiro, organizer with [1] attacks
The most target in Brazil is Multinational with [9] attacks
The most target in Brunei is Embassy Official with [5] attacks
The most target in Bulgaria is Mosque with [2] attacks
The most target in Burkina Faso is Police Station with [5] attacks
The most target in Burundi is Bar with [24] attacks
The most target in Cambodia is unit with [5] attacks
The most target in Cameroon is Civilians with [33] attacks
The most target in Canada is Mosque with [4] attacks
The most target in Central African Republic is Civilians with [25] attacks
The most target in Chad is Market with [6] attacks
The most target in Chile is Bus with [55] attacks
The most target in China is Bus with [11] attacks
The most target in Colombia is Bus with [140] attacks
The most target in Comoros is Prefecture building with [2] attacks
The most target in Costa Rica is Nicaraguan Consulate with [2] attacks
The most target in Croatia is Unit with [3] attacks
The most target in Cuba is Hotel with [6] attacks
The most target in Cyprus is Nicosia City Hall with [4] attacks
The most target in Czech Republic is Vehicles with [2] attacks
The most target in Czechoslovakia is Aircraft - Flight to Frankfurt with [1] attacks
The most target in Democratic Republic of the Congo is Civilians with [82] attacks
The most target in Denmark is Anti-Islam Writer: Lars Copenhagen with [1] attacks
The most target in Djibouti is Cafe L'Europe with [1] attacks
The most target in Dominica is Central Police Station with [1] attacks
The most target in Dominican Republic is Street with [13] attacks
The most target in East Germany (GDR) is Bank with [3] attacks
The most target in East Timor is Alfonso Guterres with [1] attacks
The most target in Ecuador is Branch with [4] attacks
The most target in Egypt is Checkpoint with [217] attacks
The most target in El Salvador is Military Unit with [220] attacks
The most target in Equatorial Guinea is The presidential compound in Malabo, Equatorial Guinea. with [1] attacks
The most target in Eritrea is A restaurant was targeted in Haykota, Gash-Barka, Eritrea. with [1] attacks
The most target in Estonia is Bus?? with [1] attacks
The most target in Ethiopia is Village with [10] attacks
The most target in Fiji is Civilian ethnic Indian males in Labasa with [1] attacks
The most target in Finland is Refugee Reception Center with [4] attacks
The most target in France is Central Tax Office with [50] attacks
The most target in French Guiana is Agriculture Bldg. with [1] attacks
The most target in French Polynesia is Faca International Airport Terminals with [1] attacks
The most target in Gabon is Activists with [1] attacks
The most target in Gambia is Gambian President with [1] attacks
The most target in Georgia is A peacekeeping station with [5] attacks
The most target in Germany is Foreigners Hostel with [22] attacks
The most target in Ghana is Vehicle, Tamale-Yendi Road with [2] attacks
The most target in Greece is store with [32] attacks
The most target in Grenada is Anky Elizabeth Nucete (10), Daughter Venezuelan charged affairs in Grenada with [1] attacks
The most target in Guadeloupe is Airport with [1] attacks
The most target in Guatemala is Military Unit with [109] attacks
The most target in Guinea is President Lansana Conte with [2] attacks
The most target in Guinea-Bissau is A presidential candidate with [1] attacks
The most target in Guyana is Telephone Junction Box with [2] attacks
The most target in Haiti is Police Station with [2] attacks
The most target in Honduras is Military Unit with [9] attacks
The most target in Hong Kong is 48,531 ton tanker World Bridge with [1] attacks
The most target in Hungary is Car dealerships with [4] attacks
The most target in Iceland is Lutheran Church with [1] attacks
The most target in India is Patrol with [253] attacks
The most target in Indonesia is 21 churches with [25] attacks
The most target in International is Tanker ship Limberg with [1] attacks
The most target in Iran is Vehicle with [8] attacks
The most target in Iraq is Civilians with [2906] attacks
The most target in Ireland is House with [28] attacks
The most target in Israel is Civilians with [82] attacks
The most target in Italy is Office with [31] attacks
The most target in Ivory Coast is Base with [6] attacks
The most target in Jamaica is Church with [2] attacks
The most target in Japan is Shinto Shrine with [9] attacks
The most target in Jordan is Offical with [4] attacks
The most target in Kazakhstan is Arms Shop with [2] attacks
The most target in Kenya is Vehicle with [34] attacks
The most target in Kosovo is Civilians with [4] attacks
The most target in Kuwait is Unit with [2] attacks
The most target in Kyrgyzstan is Law enforcement offices with [3] attacks
The most target in Laos is Bus with [2] attacks
The most target in Latvia is A railway bypass between Zemitani and Brasla stations in the area of Riga with [1] attacks
The most target in Lebanon is Patrol with [50] attacks
The most target in Lesotho is American Cultural Center with [1] attacks
The most target in Liberia is 4 Employees, U.N. Development Program with [1] attacks
The most target in Libya is Soldiers with [65] attacks
The most target in Lithuania is Border Post with [1] attacks
The most target in Luxembourg is Branch with [3] attacks
The most target in Macau is Vehicle with [4] attacks
The most target in Macedonia is Building with [3] attacks
The most target in Madagascar is 7 year old girl* with [1] attacks
The most target in Malawi is Church with [1] attacks
The most target in Malaysia is town with [5] attacks
The most target in Maldives is Motorcycle with [3] attacks
The most target in Mali is Vehicle with [41] attacks
The most target in Malta is Hotel with [3] attacks
The most target in Martinique is Building (owned by Chase Manhattan Bank) housing the U.S. Consulate with [1] attacks
The most target in Mauritania is A director of a school with [1] attacks
The most target in Mauritius is Prime Minister Sir Aeerood Jugnauth with [1] attacks
The most target in Mexico is Bus with [15] attacks
The most target in Moldova is Bridge Over Dnestr River with [2] attacks
The most target in Montenegro is Editor-in-Chief: Mihail Jovic with [1] attacks
The most target in Morocco is student member with [3] attacks
The most target in Mozambique is Bus with [11] attacks
The most target in Myanmar is Police Post with [25] attacks
The most target in Namibia is Vehicle with [4] attacks
The most target in Nepal is Office with [23] attacks
The most target in Netherlands is Mosque with [5] attacks
The most target in New Caledonia is Gendarme with [2] attacks
The most target in New Hebrides is radio station with [1] attacks
The most target in New Zealand is A scrap yard with [1] attacks
The most target in Nicaragua is Military Unit with [219] attacks
The most target in Niger is Village with [17] attacks
The most target in Nigeria is Village with [653] attacks
The most target in North Korea is Kim Chongnil Supporters with [1] attacks
The most target in North Yemen is 'Add al-Fattah Isma'il, secretery general with [1] attacks
The most target in Norway is Turkish Embassy with [3] attacks
The most target in Pakistan is Vehicle with [444] attacks
The most target in Panama is ranches with [6] attacks
The most target in Papua New Guinea is Unit with [3] attacks
The most target in Paraguay is Bus with [11] attacks
The most target in People's Republic of the Congo is Ambassador: Nahum Gershom with [1] attacks
The most target in Peru is High tension line tower with [116] attacks
The most target in Philippines is Soldiers with [138] attacks
The most target in Poland is Artur G. with [1] attacks
The most target in Portugal is Privately owned vehicle of FRG Military Personnel stationed at NATO Base, * with [8] attacks
The most target in Qatar is Civilians in Doha with [1] attacks
The most target in Republic of the Congo is Police Station with [7] attacks
The most target in Rhodesia is train with [2] attacks
The most target in Romania is A gas station in Bucharest with [1] attacks
The most target in Russia is Officers with [54] attacks
The most target in Rwanda is Civilians with [11] attacks
The most target in Saudi Arabia is Patrol with [25] attacks
The most target in Senegal is Truck with [2] attacks
The most target in Serbia is A police vehicle was targeted in the attack. with [1] attacks
The most target in Serbia-Montenegro is A police checkpoint in Veliki Trnovac with [1] attacks
The most target in Seychelles is Air India Boeing 707 (on way from Zimbabwe to Bombay) with [1] attacks
The most target in Sierra Leone is Unit with [3] attacks
The most target in Singapore is Building with [1] attacks
The most target in Slovak Republic is A pharmacy in Bratislava with [1] attacks
The most target in Slovenia is Defense Ministry with [1] attacks
The most target in Solomon Islands is Airplane belonging to Solomon Airlines with [1] attacks
The most target in Somalia is Soldiers with [173] attacks
The most target in South Africa is SAP personnel with [37] attacks
The most target in South Korea is Ambassador to South Korea: Mark Lippert with [1] attacks
The most target in South Sudan is Soldiers with [13] attacks
The most target in South Vietnam is CV-880 with [1] attacks
The most target in South Yemen is Israeli Oil Tanker Coral Sea with [1] attacks
The most target in Soviet Union is Customs Post with [5] attacks
The most target in Spain is Bank with [57] attacks
The most target in Sri Lanka is Unit with [77] attacks
The most target in St. Kitts and Nevis is Vehicle with [1] attacks
The most target in St. Lucia is Religious representatives and worshippers at the Basilica of the Immaculate Conception in Castries with [1] attacks
The most target in Sudan is Village with [62] attacks
The most target in Suriname is station with [3] attacks
The most target in Swaziland is 8 vehicles with [1] attacks
The most target in Sweden is Refugee Center with [8] attacks
The most target in Switzerland is Diplomat with [5] attacks
The most target in Syria is Neighborhood with [218] attacks
The most target in Taiwan is Pavement, major street with [11] attacks
The most target in Tajikistan is Russian Military with [10] attacks
The most target in Tanzania is Church with [10] attacks
The most target in Thailand is Patrol with [145] attacks
The most target in Togo is Home of Party official with [2] attacks
The most target in Trinidad and Tobago is Bus with [3] attacks
The most target in Tunisia is Patrol with [9] attacks
The most target in Turkey is Vehicle with [155] attacks
The most target in Turkmenistan is Saparmurat Niyazov, the President of Turkmenistan with [1] attacks
The most target in Uganda is Police Station with [7] attacks
The most target in Ukraine is Soldiers with [297] attacks
The most target in United Arab Emirates is Airliner with [1] attacks
The most target in United Kingdom is House with [61] attacks
The most target in United States is Church with [34] attacks
The most target in Uruguay is Acodike Supergas with [1] attacks
The most target in Uzbekistan is Government building in Tashkent with [2] attacks
The most target in Vanuatu is Advisor to VMF with [1] attacks
The most target in Vatican City is Pope, John Paul II (60), Head with [1] attacks
The most target in Venezuela is Bus with [8] attacks
The most target in Vietnam is Airport with [1] attacks
The most target in Wallis and Futuna is Territorial Assembly Bldg. with [1] attacks
The most target in West Bank and Gaza Strip is Soldiers with [80] attacks
The most target in West Germany (FRG) is bank with [7] attacks
The most target in Western Sahara is Patrol (all Italians) with [1] attacks
The most target in Yemen is Checkpoint with [108] attacks
The most target in Yugoslavia is Police Staion with [3] attacks
The most target in Zaire is Embassy Official with [3] attacks
The most target in Zambia is A village in Chavuma District with [8] attacks
The most target in Zimbabwe is 3 buses a moving van, some cars with [1] attacks

Q4: What is the most attack_type in each country?

In [42]:
for x in df.groupby(df.country).sum().sort_values(by="country").index:
    print("The most attack_type in",x,"is",df[df.country == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.country == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most attack_type in Afghanistan is Bombing/Explosion with [659] attacks
The most attack_type in Albania is Bombing/Explosion with [3] attacks
The most attack_type in Algeria is Bombing/Explosion with [55] attacks
The most attack_type in Angola is Bombing/Explosion with [113] attacks
The most attack_type in Argentina is Bombing/Explosion with [19] attacks
The most attack_type in Armenia is Bombing/Explosion with [1] attacks
The most attack_type in Australia is Facility/Infrastructure Attack with [8] attacks
The most attack_type in Austria is Bombing/Explosion with [5] attacks
The most attack_type in Azerbaijan is Bombing/Explosion with [1] attacks
The most attack_type in Bahamas is Bombing/Explosion with [1] attacks
The most attack_type in Bahrain is Bombing/Explosion with [28] attacks
The most attack_type in Bangladesh is Bombing/Explosion with [60] attacks
The most attack_type in Barbados is Bombing/Explosion with [1] attacks
The most attack_type in Belarus is Bombing/Explosion with [1] attacks
The most attack_type in Belgium is Bombing/Explosion with [3] attacks
The most attack_type in Belize is Assassination with [1] attacks
The most attack_type in Benin is Bombing/Explosion with [1] attacks
The most attack_type in Bhutan is Bombing/Explosion with [1] attacks
The most attack_type in Bolivia is Bombing/Explosion with [12] attacks
The most attack_type in Bosnia-Herzegovina is Bombing/Explosion with [5] attacks
The most attack_type in Botswana is Bombing/Explosion with [1] attacks
The most attack_type in Brazil is Assassination with [9] attacks
The most attack_type in Brunei is Assassination with [5] attacks
The most attack_type in Bulgaria is Bombing/Explosion with [2] attacks
The most attack_type in Burkina Faso is Armed Assault with [5] attacks
The most attack_type in Burundi is Armed Assault with [24] attacks
The most attack_type in Cambodia is Bombing/Explosion with [5] attacks
The most attack_type in Cameroon is Bombing/Explosion with [33] attacks
The most attack_type in Canada is Bombing/Explosion with [4] attacks
The most attack_type in Central African Republic is Armed Assault with [25] attacks
The most attack_type in Chad is Armed Assault with [6] attacks
The most attack_type in Chile is Bombing/Explosion with [55] attacks
The most attack_type in China is Bombing/Explosion with [11] attacks
The most attack_type in Colombia is Bombing/Explosion with [140] attacks
The most attack_type in Comoros is Facility/Infrastructure Attack with [2] attacks
The most attack_type in Costa Rica is Bombing/Explosion with [2] attacks
The most attack_type in Croatia is Bombing/Explosion with [3] attacks
The most attack_type in Cuba is Bombing/Explosion with [6] attacks
The most attack_type in Cyprus is Bombing/Explosion with [4] attacks
The most attack_type in Czech Republic is Bombing/Explosion with [2] attacks
The most attack_type in Czechoslovakia is Bombing/Explosion with [1] attacks
The most attack_type in Democratic Republic of the Congo is Armed Assault with [82] attacks
The most attack_type in Denmark is Bombing/Explosion with [1] attacks
The most attack_type in Djibouti is Bombing/Explosion with [1] attacks
The most attack_type in Dominica is Armed Assault with [1] attacks
The most attack_type in Dominican Republic is Bombing/Explosion with [13] attacks
The most attack_type in East Germany (GDR) is Facility/Infrastructure Attack with [3] attacks
The most attack_type in East Timor is Bombing/Explosion with [1] attacks
The most attack_type in Ecuador is Bombing/Explosion with [4] attacks
The most attack_type in Egypt is Bombing/Explosion with [217] attacks
The most attack_type in El Salvador is Armed Assault with [220] attacks
The most attack_type in Equatorial Guinea is Armed Assault with [1] attacks
The most attack_type in Eritrea is Bombing/Explosion with [1] attacks
The most attack_type in Estonia is Bombing/Explosion with [1] attacks
The most attack_type in Ethiopia is Bombing/Explosion with [10] attacks
The most attack_type in Fiji is Facility/Infrastructure Attack with [1] attacks
The most attack_type in Finland is Facility/Infrastructure Attack with [4] attacks
The most attack_type in France is Bombing/Explosion with [50] attacks
The most attack_type in French Guiana is Facility/Infrastructure Attack with [1] attacks
The most attack_type in French Polynesia is Facility/Infrastructure Attack with [1] attacks
The most attack_type in Gabon is Assassination with [1] attacks
The most attack_type in Gambia is Assassination with [1] attacks
The most attack_type in Georgia is Bombing/Explosion with [5] attacks
The most attack_type in Germany is Facility/Infrastructure Attack with [22] attacks
The most attack_type in Ghana is Bombing/Explosion with [2] attacks
The most attack_type in Greece is Bombing/Explosion with [32] attacks
The most attack_type in Grenada is Assassination with [1] attacks
The most attack_type in Guadeloupe is Bombing/Explosion with [1] attacks
The most attack_type in Guatemala is Assassination with [109] attacks
The most attack_type in Guinea is Assassination with [2] attacks
The most attack_type in Guinea-Bissau is Armed Assault with [1] attacks
The most attack_type in Guyana is Bombing/Explosion with [2] attacks
The most attack_type in Haiti is Assassination with [2] attacks
The most attack_type in Honduras is Bombing/Explosion with [9] attacks
The most attack_type in Hong Kong is Bombing/Explosion with [1] attacks
The most attack_type in Hungary is Bombing/Explosion with [4] attacks
The most attack_type in Iceland is Bombing/Explosion with [1] attacks
The most attack_type in India is Bombing/Explosion with [253] attacks
The most attack_type in Indonesia is Bombing/Explosion with [25] attacks
The most attack_type in International is Bombing/Explosion with [1] attacks
The most attack_type in Iran is Bombing/Explosion with [8] attacks
The most attack_type in Iraq is Bombing/Explosion with [2906] attacks
The most attack_type in Ireland is Bombing/Explosion with [28] attacks
The most attack_type in Israel is Bombing/Explosion with [82] attacks
The most attack_type in Italy is Bombing/Explosion with [31] attacks
The most attack_type in Ivory Coast is Armed Assault with [6] attacks
The most attack_type in Jamaica is Armed Assault with [2] attacks
The most attack_type in Japan is Facility/Infrastructure Attack with [9] attacks
The most attack_type in Jordan is Bombing/Explosion with [4] attacks
The most attack_type in Kazakhstan is Bombing/Explosion with [2] attacks
The most attack_type in Kenya is Bombing/Explosion with [34] attacks
The most attack_type in Kosovo is Bombing/Explosion with [4] attacks
The most attack_type in Kuwait is Bombing/Explosion with [2] attacks
The most attack_type in Kyrgyzstan is Bombing/Explosion with [3] attacks
The most attack_type in Laos is Bombing/Explosion with [2] attacks
The most attack_type in Latvia is Bombing/Explosion with [1] attacks
The most attack_type in Lebanon is Bombing/Explosion with [50] attacks
The most attack_type in Lesotho is Bombing/Explosion with [1] attacks
The most attack_type in Liberia is Armed Assault with [1] attacks
The most attack_type in Libya is Bombing/Explosion with [65] attacks
The most attack_type in Lithuania is Bombing/Explosion with [1] attacks
The most attack_type in Luxembourg is Bombing/Explosion with [3] attacks
The most attack_type in Macau is Bombing/Explosion with [4] attacks
The most attack_type in Macedonia is Bombing/Explosion with [3] attacks
The most attack_type in Madagascar is Bombing/Explosion with [1] attacks
The most attack_type in Malawi is Armed Assault with [1] attacks
The most attack_type in Malaysia is Bombing/Explosion with [5] attacks
The most attack_type in Maldives is Facility/Infrastructure Attack with [3] attacks
The most attack_type in Mali is Bombing/Explosion with [41] attacks
The most attack_type in Malta is Bombing/Explosion with [3] attacks
The most attack_type in Martinique is Bombing/Explosion with [1] attacks
The most attack_type in Mauritania is Armed Assault with [1] attacks
The most attack_type in Mauritius is Assassination with [1] attacks
The most attack_type in Mexico is Armed Assault with [15] attacks
The most attack_type in Moldova is Bombing/Explosion with [2] attacks
The most attack_type in Montenegro is Bombing/Explosion with [1] attacks
The most attack_type in Morocco is Bombing/Explosion with [3] attacks
The most attack_type in Mozambique is Armed Assault with [11] attacks
The most attack_type in Myanmar is Bombing/Explosion with [25] attacks
The most attack_type in Namibia is Bombing/Explosion with [4] attacks
The most attack_type in Nepal is Bombing/Explosion with [23] attacks
The most attack_type in Netherlands is Bombing/Explosion with [5] attacks
The most attack_type in New Caledonia is Bombing/Explosion with [2] attacks
The most attack_type in New Hebrides is Bombing/Explosion with [1] attacks
The most attack_type in New Zealand is Unarmed Assault with [1] attacks
The most attack_type in Nicaragua is Armed Assault with [219] attacks
The most attack_type in Niger is Armed Assault with [17] attacks
The most attack_type in Nigeria is Armed Assault with [653] attacks
The most attack_type in North Korea is Armed Assault with [1] attacks
The most attack_type in North Yemen is Assassination with [1] attacks
The most attack_type in Norway is Facility/Infrastructure Attack with [3] attacks
The most attack_type in Pakistan is Bombing/Explosion with [444] attacks
The most attack_type in Panama is Bombing/Explosion with [6] attacks
The most attack_type in Papua New Guinea is Armed Assault with [3] attacks
The most attack_type in Paraguay is Armed Assault with [11] attacks
The most attack_type in People's Republic of the Congo is Assassination with [1] attacks
The most attack_type in Peru is Bombing/Explosion with [116] attacks
The most attack_type in Philippines is Armed Assault with [138] attacks
The most attack_type in Poland is Bombing/Explosion with [1] attacks
The most attack_type in Portugal is Bombing/Explosion with [8] attacks
The most attack_type in Qatar is Bombing/Explosion with [1] attacks
The most attack_type in Republic of the Congo is Bombing/Explosion with [7] attacks
The most attack_type in Rhodesia is Bombing/Explosion with [2] attacks
The most attack_type in Romania is Assassination with [1] attacks
The most attack_type in Russia is Bombing/Explosion with [54] attacks
The most attack_type in Rwanda is Armed Assault with [11] attacks
The most attack_type in Saudi Arabia is Bombing/Explosion with [25] attacks
The most attack_type in Senegal is Armed Assault with [2] attacks
The most attack_type in Serbia is Bombing/Explosion with [1] attacks
The most attack_type in Serbia-Montenegro is Bombing/Explosion with [1] attacks
The most attack_type in Seychelles is Bombing/Explosion with [1] attacks
The most attack_type in Sierra Leone is Armed Assault with [3] attacks
The most attack_type in Singapore is Bombing/Explosion with [1] attacks
The most attack_type in Slovak Republic is Bombing/Explosion with [1] attacks
The most attack_type in Slovenia is Bombing/Explosion with [1] attacks
The most attack_type in Solomon Islands is Assassination with [1] attacks
The most attack_type in Somalia is Bombing/Explosion with [173] attacks
The most attack_type in South Africa is Bombing/Explosion with [37] attacks
The most attack_type in South Korea is Facility/Infrastructure Attack with [1] attacks
The most attack_type in South Sudan is Armed Assault with [13] attacks
The most attack_type in South Vietnam is Bombing/Explosion with [1] attacks
The most attack_type in South Yemen is Bombing/Explosion with [1] attacks
The most attack_type in Soviet Union is Bombing/Explosion with [5] attacks
The most attack_type in Spain is Bombing/Explosion with [57] attacks
The most attack_type in Sri Lanka is Bombing/Explosion with [77] attacks
The most attack_type in St. Kitts and Nevis is Unarmed Assault with [1] attacks
The most attack_type in St. Lucia is Armed Assault with [1] attacks
The most attack_type in Sudan is Armed Assault with [62] attacks
The most attack_type in Suriname is Armed Assault with [3] attacks
The most attack_type in Swaziland is Bombing/Explosion with [1] attacks
The most attack_type in Sweden is Facility/Infrastructure Attack with [8] attacks
The most attack_type in Switzerland is Bombing/Explosion with [5] attacks
The most attack_type in Syria is Bombing/Explosion with [218] attacks
The most attack_type in Taiwan is Facility/Infrastructure Attack with [11] attacks
The most attack_type in Tajikistan is Bombing/Explosion with [10] attacks
The most attack_type in Tanzania is Bombing/Explosion with [10] attacks
The most attack_type in Thailand is Bombing/Explosion with [145] attacks
The most attack_type in Togo is Bombing/Explosion with [2] attacks
The most attack_type in Trinidad and Tobago is Assassination with [3] attacks
The most attack_type in Tunisia is Armed Assault with [9] attacks
The most attack_type in Turkey is Bombing/Explosion with [155] attacks
The most attack_type in Turkmenistan is Assassination with [1] attacks
The most attack_type in Uganda is Armed Assault with [7] attacks
The most attack_type in Ukraine is Bombing/Explosion with [297] attacks
The most attack_type in United Arab Emirates is Bombing/Explosion with [1] attacks
The most attack_type in United Kingdom is Bombing/Explosion with [61] attacks
The most attack_type in United States is Bombing/Explosion with [34] attacks
The most attack_type in Uruguay is Bombing/Explosion with [1] attacks
The most attack_type in Uzbekistan is Bombing/Explosion with [2] attacks
The most attack_type in Vanuatu is Hostage Taking (Barricade Incident) with [1] attacks
The most attack_type in Vatican City is Assassination with [1] attacks
The most attack_type in Venezuela is Bombing/Explosion with [8] attacks
The most attack_type in Vietnam is Facility/Infrastructure Attack with [1] attacks
The most attack_type in Wallis and Futuna is Facility/Infrastructure Attack with [1] attacks
The most attack_type in West Bank and Gaza Strip is Armed Assault with [80] attacks
The most attack_type in West Germany (FRG) is Bombing/Explosion with [7] attacks
The most attack_type in Western Sahara is Bombing/Explosion with [1] attacks
The most attack_type in Yemen is Bombing/Explosion with [108] attacks
The most attack_type in Yugoslavia is Armed Assault with [3] attacks
The most attack_type in Zaire is Bombing/Explosion with [3] attacks
The most attack_type in Zambia is Bombing/Explosion with [8] attacks
The most attack_type in Zimbabwe is Bombing/Explosion with [1] attacks

Q5: what is the most Region has kills?

In [43]:
pltbar(df.groupby(df.region).sum().sort_values(by="nkill", ascending=False)[:5].nkill.index,  df.groupby(df.region).sum().sort_values(by="nkill", ascending=False)[:5].nkill.values, "Region", "#of kills", "Top 5 Regions has kills")
plt.xticks(rotation = 45);
df.groupby(df.region).sum().sort_values(by="nkill", ascending=False)[:5].nkill
Out[43]:
region
Middle East & North Africa     115913
South Asia                      85891
Sub-Saharan Africa              63695
South America                   22832
Central America & Caribbean     21118
Name: nkill, dtype: int32

Q6: What is the top 5 Regions in average kills by attack?

In [44]:
pltbar(df.groupby(df.region).mean().sort_values("nkill", ascending=False)[:5].index, df.groupby(df.region).mean().sort_values("nkill", ascending=False).nkill[:5].values, "Region", "Average kills by attack", "Top 5 Regions in average kills by attack")
plt.xticks(rotation = 45);
df.groupby(df.region).mean().sort_values("nkill", ascending=False)[:5].nkill
Out[44]:
region
Sub-Saharan Africa             4.706295
Central America & Caribbean    3.318875
Middle East & North Africa     2.806882
South Asia                     2.277249
East Asia                      1.752000
Name: nkill, dtype: float64

Q7: What is the most target in each Region?

In [45]:
for x in df.groupby(df.region).sum().sort_values(by="region").index:
    print("The most target in",x,"is",df[df.region == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.region == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most target in Australasia & Oceania is Church with [8] attacks
The most target in Central America & Caribbean is Military Unit with [557] attacks
The most target in Central Asia is Russian Military with [12] attacks
The most target in East Asia is Pavement, major street with [11] attacks
The most target in Eastern Europe is Soldiers with [304] attacks
The most target in Middle East & North Africa is Civilians with [3428] attacks
The most target in North America is Church with [37] attacks
The most target in South America is Bus with [303] attacks
The most target in South Asia is Civilians with [1255] attacks
The most target in Southeast Asia is Patrol with [255] attacks
The most target in Sub-Saharan Africa is Village with [911] attacks
The most target in Western Europe is Bank with [142] attacks

Q8: What is the most attack_type in each Region?

In [46]:
for x in df.groupby(df.region).sum().sort_values(by="region").index:
    print("The most attack_type in",x,"is",df[df.region == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.region == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most attack_type in Australasia & Oceania is Facility/Infrastructure Attack with [8] attacks
The most attack_type in Central America & Caribbean is Armed Assault with [557] attacks
The most attack_type in Central Asia is Bombing/Explosion with [12] attacks
The most attack_type in East Asia is Bombing/Explosion with [11] attacks
The most attack_type in Eastern Europe is Bombing/Explosion with [304] attacks
The most attack_type in Middle East & North Africa is Bombing/Explosion with [3428] attacks
The most attack_type in North America is Bombing/Explosion with [37] attacks
The most attack_type in South America is Bombing/Explosion with [303] attacks
The most attack_type in South Asia is Bombing/Explosion with [1255] attacks
The most attack_type in Southeast Asia is Bombing/Explosion with [255] attacks
The most attack_type in Sub-Saharan Africa is Armed Assault with [911] attacks
The most attack_type in Western Europe is Bombing/Explosion with [142] attacks

Multi-Variate Analysis¶

Q9: What is the top 5 states & cities in Iraq has #of kills?

In [47]:
df[df.country == "Iraq"].groupby("state").sum().nkill.sort_values(ascending = False)[:5]
Out[47]:
state
Baghdad     19405
Nineveh     13358
Al Anbar     9837
Saladin      9036
Diyala       6971
Name: nkill, dtype: int32
In [48]:
df[df.country == "Iraq"].groupby("city").sum().nkill.sort_values(ascending = False)[:5]
Out[48]:
city
Baghdad    19343
Mosul       6297
Tikrit      2526
Ramadi      2026
Baqubah     1680
Name: nkill, dtype: int32

Q10: What is the most target & attack_type in Middle East countries?

In [49]:
for x in df[df.region == "Middle East & North Africa"].groupby(df.country).sum().sort_values(by="nkill", ascending = False).index:
    print("The most target in",x,"is",df[df.country == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.country == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].nkill.values,"attacks")
The most target in Iraq is Civilians with [2906] attacks
The most target in Syria is Neighborhood with [218] attacks
The most target in Algeria is Unit with [55] attacks
The most target in Yemen is Checkpoint with [108] attacks
The most target in Turkey is Vehicle with [155] attacks
The most target in Lebanon is Patrol with [50] attacks
The most target in Egypt is Checkpoint with [217] attacks
The most target in Libya is Soldiers with [65] attacks
The most target in Israel is Civilians with [82] attacks
The most target in Iran is Vehicle with [8] attacks
The most target in West Bank and Gaza Strip is Soldiers with [80] attacks
The most target in Saudi Arabia is Patrol with [25] attacks
The most target in Tunisia is Patrol with [9] attacks
The most target in Jordan is Offical with [4] attacks
The most target in United Arab Emirates is Airliner with [1] attacks
The most target in Morocco is student member with [3] attacks
The most target in Kuwait is Unit with [2] attacks
The most target in Bahrain is Officers with [28] attacks
The most target in Qatar is Civilians in Doha with [1] attacks
The most target in International is Tanker ship Limberg with [1] attacks
The most target in North Yemen is 'Add al-Fattah Isma'il, secretery general with [1] attacks
The most target in South Yemen is Israeli Oil Tanker Coral Sea with [1] attacks
The most target in Western Sahara is Patrol (all Italians) with [1] attacks
In [50]:
for x in df[df.region == "Middle East & North Africa"].groupby(df.country).count().sort_values(by="day", ascending = False).index:
    print("The most attack_type in",x,"is",df[df.country == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.country == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most attack_type in Iraq is Bombing/Explosion with [16187] attacks
The most attack_type in Turkey is Bombing/Explosion with [1647] attacks
The most attack_type in Yemen is Bombing/Explosion with [1098] attacks
The most attack_type in Algeria is Bombing/Explosion with [958] attacks
The most attack_type in Lebanon is Bombing/Explosion with [1214] attacks
The most attack_type in Egypt is Bombing/Explosion with [881] attacks
The most attack_type in West Bank and Gaza Strip is Armed Assault with [802] attacks
The most attack_type in Libya is Bombing/Explosion with [831] attacks
The most attack_type in Israel is Bombing/Explosion with [1164] attacks
The most attack_type in Syria is Bombing/Explosion with [1289] attacks
The most attack_type in Iran is Bombing/Explosion with [260] attacks
The most attack_type in Saudi Arabia is Bombing/Explosion with [167] attacks
The most attack_type in Bahrain is Bombing/Explosion with [102] attacks
The most attack_type in Jordan is Bombing/Explosion with [34] attacks
The most attack_type in Tunisia is Armed Assault with [32] attacks
The most attack_type in Kuwait is Bombing/Explosion with [25] attacks
The most attack_type in Morocco is Bombing/Explosion with [14] attacks
The most attack_type in United Arab Emirates is Bombing/Explosion with [8] attacks
The most attack_type in Qatar is Bombing/Explosion with [2] attacks
The most attack_type in North Yemen is Assassination with [2] attacks
The most attack_type in Western Sahara is Bombing/Explosion with [2] attacks
The most attack_type in South Yemen is Bombing/Explosion with [1] attacks
The most attack_type in International is Bombing/Explosion with [1] attacks

Q11: What is the most target & attack_type in Iraq states?

In [51]:
for x in df[df.country == "Iraq"].groupby(df.state).count().sort_values(by="day", ascending = False).index:
    print("The most target in",x,"is",df[df.state == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.state == x].groupby("target").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most target in Baghdad is Civilians with [1411] attacks
The most target in Saladin is Patrol with [266] attacks
The most target in Diyala is Civilians with [409] attacks
The most target in Nineveh is Civilians with [223] attacks
The most target in Al Anbar is Civilians with [231] attacks
The most target in Kirkuk is Civilians with [134] attacks
The most target in Babil is Civilians with [165] attacks
The most target in Basra is Civilians with [9] attacks
The most target in Karbala is Civilians with [17] attacks
The most target in Wasit is Civilians with [15] attacks
The most target in At Tamim is Police patrol in Kirkuk, Iraq with [3] attacks
The most target in Arbil is Officer with [8] attacks
The most target in Dhi Qar is Civilians with [8] attacks
The most target in Sulaymaniyah is Members with [4] attacks
The most target in Najaf is Civilians with [4] attacks
The most target in Al Qadisiyah is Checkpoint with [5] attacks
The most target in Maysan is Civilians with [4] attacks
The most target in Qadisiyah is Members with [2] attacks
The most target in Dihok is Vehicle with [3] attacks
The most target in Muthanna is Checkpoint with [2] attacks
The most target in NIneveh is Camp with [1] attacks
The most target in Khost is Vehicle with [25] attacks
In [52]:
for x in df[df.country == "Iraq"].groupby(df.state).count().sort_values(by="day", ascending = False).index:
    print("The most attack_type in",x,"is",df[df.state == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].index[0],"with",df[df.state == x].groupby("attack_type").count().sort_values('nkill',ascending = False)[:1].day.values,"attacks")
The most attack_type in Baghdad is Bombing/Explosion with [5962] attacks
The most attack_type in Saladin is Bombing/Explosion with [2135] attacks
The most attack_type in Diyala is Bombing/Explosion with [2030] attacks
The most attack_type in Nineveh is Bombing/Explosion with [1653] attacks
The most attack_type in Al Anbar is Bombing/Explosion with [1988] attacks
The most attack_type in Kirkuk is Bombing/Explosion with [938] attacks
The most attack_type in Babil is Bombing/Explosion with [882] attacks
The most attack_type in Basra is Bombing/Explosion with [139] attacks
The most attack_type in Karbala is Bombing/Explosion with [100] attacks
The most attack_type in Wasit is Bombing/Explosion with [74] attacks
The most attack_type in At Tamim is Bombing/Explosion with [54] attacks
The most attack_type in Arbil is Bombing/Explosion with [61] attacks
The most attack_type in Dhi Qar is Bombing/Explosion with [43] attacks
The most attack_type in Sulaymaniyah is Bombing/Explosion with [26] attacks
The most attack_type in Najaf is Bombing/Explosion with [30] attacks
The most attack_type in Al Qadisiyah is Bombing/Explosion with [20] attacks
The most attack_type in Maysan is Bombing/Explosion with [16] attacks
The most attack_type in Qadisiyah is Armed Assault with [11] attacks
The most attack_type in Dihok is Bombing/Explosion with [12] attacks
The most attack_type in Muthanna is Bombing/Explosion with [14] attacks
The most attack_type in NIneveh is Hostage Taking (Kidnapping) with [1] attacks
The most attack_type in Khost is Bombing/Explosion with [277] attacks
In [53]:
df.to_csv("Modified")

Conclusions:¶

After investigating the data frame we knew the following:¶

  • The most Region has terrorism attacks and killed people in the world is Middle East & North Africa with $41296$ attacks and $115913$ peoples killed by terrorists.
  • The most Country has terrorism attacks and killed people in the Middle East and the World is Iraq with $21066$ attacks and $68408$ peoples killed by terrorists.
  • The most Governate has terrorism attacks in Iraq and the World is Baghdad with $7129$ attacks.
  • The most Weapons used in the attacks is Bombing/Explosion with $74250$ attacks using this weapon.
  • The most Targets by Terrorists is Civilians with $5688$ attacks on it.
  • The most country has #of kills per attack is Barbados with an average $25$ kills per attack.
  • The most Region has #of kills per attack is Sub-Saharan Africa with an average $4.7$ kills per attack.

Recommendation:
Finally, Iraq faced a fatal war caused by the USA, which caused immense suffering and had far-reaching consequences for the lives of its people. The country's infrastructure has been severely damaged. Despite these challenges, the people of Iraq have shown remarkable resilience, and determination in the face of adversity and terrorism. Ultimately, it is only through cooperation and dialogue that a lasting solution can be found to end the suffering caused by this devastating war.

Data Limitation¶

As I said before the dataset is not considering the World Wars as terrorist acts and did not waste the lives of millions of people in the other hand it considers the war in Iraq as a terrorist act, which is very confusing for me actually.